{{define "title"}}LUCI Scheduler :: {{.Job.ProjectID}} :: {{.Job.JobName}}{{end}}

{{define "head"}}
<style type="text/css">
#invocations-table {
  table-layout: fixed;
}
.underline {
  text-decoration: underline !important;
}

#invocations-table td.long {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

nav.top-pager ul.pager {
  margin-top: 0px;
  margin-bottom: 10px;
}

nav.bottom-pager ul.pager {
  margin-top: 10px;
  margin-bottom: 0px;
}

#paused-alert {
  margin-top: 10px;
  margin-bottom: 5px;
}

.small-hr {
  margin-top: 10px;
  margin-bottom: 10px;
}
</style>
{{end}}


{{define "invocations-list"}}
  {{range .Second }}
    <tr class="{{.RowClass}}">
      <td><a href="/jobs/{{$.First.ProjectID}}/{{$.First.JobName}}/{{.InvID}}">{{.InvID}}</a></td>
      <td>{{.Started}}</td>
      <td class="long" title="{{.TriggeredBy}}">{{.TriggeredBy}}</td>
      <td>{{.Duration}}</td>
      <td>
      {{if .ViewURL}}
        <a href="{{.ViewURL}}" target="_blank" class="underline label {{.LabelClass}}">{{.Status}}</a>
      {{else}}
        <span class="label {{.LabelClass}}">{{.Status}}</span>
      {{end}}
      </td>
    </tr>
  {{end}}
{{end}}


{{define "pager"}}
  <ul class="pager">
    {{if .PrevCursor}}
      <li class="previous">
        {{if eq .PrevCursor "NULL"}}
        <a href="/jobs/{{$.Job.ProjectID}}/{{$.Job.JobName}}">
        {{else}}
        <a href="/jobs/{{$.Job.ProjectID}}/{{$.Job.JobName}}?c={{.PrevCursor}}">
        {{end}}
          <span aria-hidden="true">&larr;</span> Newer
        </a>
      </li>
    {{else}}
      <li class="previous disabled">
        <a href="#"><span aria-hidden="true">&larr;</span> Newer</a>
      </li>
    {{end}}
    {{if .NextCursor}}
      <li class="next">
        <a href="/jobs/{{$.Job.ProjectID}}/{{$.Job.JobName}}?c={{.NextCursor}}">
          Older <span aria-hidden="true">&rarr;</span>
        </a>
      </li>
    {{else}}
      <li class="next disabled">
        <a href="#">Older <span aria-hidden="true">&rarr;</span></a>
      </li>
    {{end}}
  </ul>
{{end}}


{{define "content"}}

<ol class="breadcrumb">
  <li class="breadcrumb-item"><a href="/">All projects</a></li>
  <li class="breadcrumb-item"><a href="/jobs/{{.Job.ProjectID}}">{{.Job.ProjectID}}</a></li>
  <li class="breadcrumb-item active">{{template "job-id-static" .Job}}</li>
</ol>

<div class="row">
  <div class="col-sm-3"><b>State:</b>
    <span class="label {{.Job.LabelClass}}">{{.Job.State}}</span>
  </div>
  <div class="col-sm-3"><b>Schedule:</b> {{.Job.Schedule}}</div>
  <div class="col-sm-3"><b>Next run:</b> {{.Job.NextRun}}</div>
  <div class="col-sm-3"><b>Actions:</b>{{template "job-action-buttons" .Job}}</div>
</div>

{{if .Job.Paused}}
<div class="row">
  <div class="col-sm-12">
    <div class="alert alert-warning" role="alert" id="paused-alert">
      <b>Paused by {{.Job.PausedBy}} {{.Job.PausedWhen}}:</b> {{.Job.PausedReason}}
    </div>
  </div>
</div>
{{end}}

<div class="row">
  <div class="col-sm-12">
    <hr class="small-hr">
  </div>
</div>

{{if .ShowJobHeader}}

  <h4>Definition
  {{if .Job.RevisionURL}}
    (rev <a href="{{.Job.RevisionURL}}" target="_blank">{{.Job.Revision}}</a>)
  {{else}}
    (rev {{.Job.Revision}})
  {{end}}
  </h4>
  <div class="row">
    <div class="col-sm-6">
      <h5>Task</h5>
      <pre>{{.Job.Definition}}</pre>
    </div>
    <div class="col-sm-6">
      <h5>Triggering policy</h5>
      <pre>{{.Job.Policy}}</pre>
    </div>
  </div>

  {{if .Job.TriageLog.Available}}
  <div class="row">
    <div class="col-sm-12">
      <h5>Last triage ({{.Job.TriageLog.LastTriage}})</h5>
      {{if .Job.TriageLog.Stale}}
      <div class="alert alert-danger" role="alert">
        This log is stale! The log is {{.Job.TriageLog.Staleness}} older than
        the expected. Please investigate GAE logs to see why the triage log is
        not being updated.
      </div>
      {{end}}
      <pre>{{.Job.TriageLog.DebugLog}}</pre>
    </div>
  </div>
  {{end}}

  {{if .PendingTriggers}}
  <h4>Pending triggers</h4>
  <div class="row">
    <div class="col-sm-12">
      {{template "triggers-list" .PendingTriggers}}
    </div>
  </div>
  {{end}}

  <div class="row">
    <div class="col-sm-12">
      <hr class="small-hr">
    </div>
  </div>

{{end}}

<div class="row">
  <div class="col-sm-12">
    <nav class="top-pager">{{template "pager" .}}</nav>
    <table class="table table-condensed" id="invocations-table">
      <thead>
        <tr>
          <th class="col-lg-2">ID</th>
          <th class="col-lg-2">Started</th>
          <th class="col-lg-3">Triggered by</th>
          <th class="col-lg-2">Duration</th>
          <th class="col-lg-2">Status</th>
        </tr>
      </thead>
      <tbody>
      {{if .InvocationsActive}}
        {{template "invocations-list" Pair .Job .InvocationsActive}}
        <tr>
          <td colspan="5">
            <hr style="margin-top: 2px; margin-bottom: 2px;"/>
          </td>
        </tr>
      {{end}}
      {{template "invocations-list" Pair .Job .InvocationsLog}}
      </tbody>
    </table>
    <nav class="bottom-pager">{{template "pager" .}}</nav>
  </div>
</div>

{{end}}
